package com.wanggan.rmi;

import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import com.wanggan.rmi.model.User;
import com.wanggan.rmi.service.HelloService;
import com.wanggan.rmi.service.UserService;
import com.wanggan.rmi.util.RegistryUtil;

/**
 * @author wanggan
 */
public class RmiClient {
    
    public static void main(String[] args) {
//        System.setProperty("java.security.policy", "AllPermission.policy");
        // TODO Auto-generated method stub
        
        
        Registry registry = RegistryUtil.getRegistry();
        User user = null;
    
        try {
            UserService userService = (UserService) registry.lookup("UserService");
            
//            user = userService.getById(1);
            user = userService.getByUsername("test");
            System.out.println(user.toString());
            
            Integer count = userService.getUserCount();
            System.out.println(count);
            
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (NotBoundException e) {
            e.printStackTrace();
        }
    
    
    }
}
